package com.example.guavaSrudy.basicCollections;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.sun.org.apache.bcel.internal.generic.GOTO;
import org.apache.commons.lang3.StringEscapeUtils;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class GuavaBasicUse {

    public static void main(String[] args) {

        //定义script的正则表达式，去除js可以防止注入
        // System.out.println(a.trim());

//        List<Integer> collect = IntStream.range(1, 6).mapToObj(x->x + 1 ).collect(Collectors.toList());
//        List<Integer> collect2 = IntStream.range(1, 2).mapToObj(x->x + 1 ).collect(Collectors.toList());
//        flAG:for (int a :collect) {
//            for (int b :collect2){
//                if(a == 4){
//                    continue flAG;
//                }
//                System.out.println("B:::"+b);
//                System.out.println("A:::"+a);
//            }
//            System.out.println("外出"+a);
//        }
//
//        Calendar cal = Calendar.getInstance();
//        String fr = cal.getDisplayName(cal.MONTH, Calendar.LONG, new Locale("FR"));
//        Set<String> mes1 = Sets.newHashSet("1","2","3","6");
//        Set<String> mes2 = Sets.newHashSet("1","2");
//        Sets.SetView<String> difference = Sets.difference(mes1, mes2);
//        Sets.SetView<String> strings = Sets.symmetricDifference(mes1, mes2);
//        Sets.SetView<String> intersection = Sets.intersection(mes1, mes2);
//        Sets.SetView<String> union = Sets.union(mes1, mes2);
//        System.out.println(difference.toString());
//        System.out.println((Set)strings.immutableCopy());
//        System.out.println("intersection:"+intersection);
//        System.out.println("union:"+union);
//        List<Book> books = GuavaBasicUse.getBooks();
//        Set<Book> mes2 = Sets.newHashSet(books);
//        Book book4 = new Book("perfect121312","风云","玄幻");
//        Set<Book> mes3 = Sets.newHashSet(books);
//        mes3.add(book4);
//        Sets.SetView<Book> intersection = Sets.intersection(mes3, mes2);
//        System.out.println(intersection);
//        /**
//         * Maps.uniqueIndex 使用
//         */
//        Map<String,Book> bookMap = Maps.uniqueIndex(books.iterator(),new Function<Book, String>(){
//            @Override
//            public String apply( Book input) {
//                return input.getIsbn();
//            }
//        });
//        transform:
//        System.out.println("uniqueIndex:"+bookMap);
//        Set<String> getkeys = GuavaBasicUse.getkeys();
//        /**
//         * asMap使用
//         */
//        Map<String, Book> asmaps = Maps.asMap(getkeys, book -> new Book("yes"+book,"哈利珀特"+book,"科幻"+book));
//        System.out.println("asMap:"+asmaps);
//        /**
//         * 转换值
//         */
//        Map<String, Object> transform = Maps.transformEntries(asmaps, (s, book) -> {
//            book.setName("改变");
//            return book;
//        });
//        System.out.println("transform:"+transform);
//        transform = Maps.transformValues(asmaps, book -> {
//            book.setName("second change");
//            return book;
//        });
//
//        System.out.println("transform:"+transform);
    }

    private static List<Book> getBooks() {
        Book book1 = new Book("yes","哈利珀特","科幻");
        Book book2 = new Book("no","汤姆和杰瑞","动画");
        Book book3 = new Book("good","拯救大兵","战争");
        Book book4 = new Book("perfect","风云","玄幻1");
        List<Book> objects = Lists.newArrayList(book1,book2,book3,book4);
        return objects;
    }

    private static Set<String> getkeys() {

        Set<String> objects = Sets.newHashSet("1","2","3","4");
        return objects;
    }

}